#include "desktop_page.h"


static const char* TAG = "lvgl_project";

static lv_style_t style_bg;
static lv_style_t style_indic;

#define desktop_Button_Num 13

lv_obj_t* lvgl_desktop_main_cont = NULL;
lv_obj_t  lvgl_desktop_style;
lv_style_t lvgl_desktop_BeiJing_style;
lv_style_t lvgl_WuBianKuang_cont_style;

lv_obj_t* lvgl_desktop_Button[desktop_Button_Num];
lv_obj_t* lvgl_desktop_Label[desktop_Button_Num];
lv_style_t lvgl_desktop_Button_style[desktop_Button_Num];


lv_area_t desktop_BUTTON_area[] =
{
    {5,5,125,65},{135,5,100,65},
    {5,75,155,65},{165,75,70,65},
    {5,145,70,80},{80,145,155,80},
    {5,230,113,75},{123,230,112,75},
    {5,310,155,65},{165,310,70,65},
    {5,380,113,80},{123,380,113,80},

    {5,465,230,130},
};

static void btns_event_cb(lv_event_t* e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t* btn = lv_event_get_target(e);
    if (code == LV_EVENT_CLICKED) {
        lv_page_load(MAIN_PAGE, WEATHER_RAGE);
    }
}



void lv_desktop_create(lv_obj_t* obj)
{
    printf("lv_desktop_create");
    lv_style_init(&lvgl_desktop_BeiJing_style);
    lv_style_init(&lvgl_desktop_style);
    //渐变色
    lv_style_set_bg_opa(&lvgl_desktop_BeiJing_style, LV_OPA_COVER);
    //设置控件背景色
    lv_style_set_bg_color(&lvgl_desktop_BeiJing_style, lv_color_black());
    lv_obj_add_style(lv_scr_act(), &lvgl_desktop_BeiJing_style, 0);//设置样式

    lv_style_set_bg_opa(&lvgl_desktop_style, LV_OPA_COVER);
    //设置控件背景色
    lv_style_set_bg_color(&lvgl_desktop_style, lv_color_black());
    lv_style_set_bg_grad_dir(&lvgl_desktop_style, LV_GRAD_DIR_VER);//渐变方向

    lv_style_set_bg_main_stop(&lvgl_desktop_style, 10);
    lv_style_set_bg_main_stop(&lvgl_desktop_style, 100);

    lvgl_desktop_main_cont = obj;

    lv_obj_set_pos(lvgl_desktop_main_cont, 0, 0);
    lv_obj_set_size(lvgl_desktop_main_cont, lv_obj_get_width(lv_scr_act()), 280);
    lv_obj_add_style(lvgl_desktop_main_cont, &lvgl_desktop_style, 0);

    for (int i = 0; i < desktop_Button_Num; i++)
    {
        lv_style_init(&lvgl_desktop_Button_style[i]);
        lv_style_init(&lvgl_WuBianKuang_cont_style);
        lv_style_set_radius(&lvgl_WuBianKuang_cont_style, 0);
        lv_style_set_border_opa(&lvgl_WuBianKuang_cont_style, 255);//边框透明度
        lv_style_set_border_width(&lvgl_WuBianKuang_cont_style, 0);//边框宽度
        lv_style_set_border_side(&lvgl_WuBianKuang_cont_style, LV_BORDER_SIDE_NONE);
        lv_style_set_pad_top(&lvgl_WuBianKuang_cont_style, 0);//内边距上侧尺寸
        lv_style_set_pad_bottom(&lvgl_WuBianKuang_cont_style, 0);//内边距下侧尺寸
        lv_style_set_pad_left(&lvgl_WuBianKuang_cont_style, 0);//内边距左侧尺寸
        lv_style_set_pad_right(&lvgl_WuBianKuang_cont_style, 0);//内边距右侧尺寸

        lvgl_desktop_Button[i] = lv_btn_create(lvgl_desktop_main_cont);
        lv_obj_set_pos(lvgl_desktop_Button[i], desktop_BUTTON_area[i].x1, desktop_BUTTON_area[i].y1);
        lv_obj_set_size(lvgl_desktop_Button[i], desktop_BUTTON_area[i].x2, desktop_BUTTON_area[i].y2);
        lv_obj_add_style(lvgl_desktop_Button[i], &lvgl_desktop_Button_style[i], 0);
        lv_obj_add_event_cb(lvgl_desktop_Button[i], btns_event_cb, LV_EVENT_ALL, NULL);
    }
    //lv_obj_clear_flag(obj, LV_OBJ_FLAG_HIDDEN);
}

void lv_desktop_entry_ani(lv_obj_t* obj)
{
    lv_anim_t ani;
    lvAnimationMovDown(&ani, obj, LV_VER_RES);
    lv_obj_clear_flag(obj, LV_OBJ_FLAG_HIDDEN);
}
